package com.itheima.controller;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.ProjectReview;
import com.itheima.entity.ProjectReviewProgress;
import com.itheima.pojo.po.ProjectReviewProgressPo;
import com.itheima.service.IProjectReviewProgressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.itheima.utils.Result;

import java.util.List;

/**
 * 项目审核进度Controller
 *
 * @author guanhuaer
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/progress")
public class ProjectReviewProgressController
{
    @Autowired
    private IProjectReviewProgressService projectReviewProgressService;


    // 根据id查询
    @GetMapping("/list")
    @ApiOperation(value = "根据项目id查询数据")
    public Result findById(@RequestParam Long projectId) {
        return Result.success(projectReviewProgressService.selectProjectList(projectId));
    }

    // 根据id查询
    @GetMapping("/projectIds")
    @ApiOperation(value = "根据项目ids查询数据")
    public Result findByProjectIds(@RequestParam Integer[] projectIds) {
        return Result.success(projectReviewProgressService.selectProjectIdsList(projectIds));
    }

    //新增
    @PostMapping
    @ApiOperation(value = "新增项目审核过程", notes = "新增项目审核进度")
    public Result add(@RequestBody ProjectReviewProgress projectReviewProgress) {
        return Result.success(projectReviewProgressService.insertProjectReviewProgress(projectReviewProgress));
    }

    //新增
    @PostMapping("/review")
    @ApiOperation(value = "新增项目审核进度", notes = "新增项目审核进度")
    public Result review(@RequestBody ProjectReview projectReview) {
        return Result.success(projectReviewProgressService.insertProjectReview(projectReview));
    }

    //修改
    @PutMapping
    @ApiOperation(value = "修改项目审核进度", notes = "修改项目审核进度")
    public Result update(@RequestBody ProjectReviewProgress projectReviewProgress) {
        return Result.success(projectReviewProgressService.updateProjectReviewProgress(projectReviewProgress));
    }

    //审核
    @PostMapping("/audit")
    @ApiOperation(value = "审核")
    public Result audit(@RequestBody ProjectReviewProgressPo progressPo) {
        projectReviewProgressService.projectAudit(progressPo);
        return Result.success();
    }

    // 根据用户名查询项目id列表
    @GetMapping("/username")
    @ApiOperation("根据用户名查询项目id列表")
    public Result selectIdByUsername(@RequestParam(value = "username") String username){
        if (username.equals("") || username==null){
            return Result.error(MessageConstant.ACCOUNT_CHANSHU);
        }
        return Result.success(projectReviewProgressService.selectIdsByUsername(username));
    }
}
